import * as React from 'react';
import {
  Component
} from 'react';

import Root from './layout/root';
import NotFound from './404';
import LogIn from './login';
import Logout from './logout';
import Register from './register';
import GetPassword from './getpwd';
import {getRoute} from './admin/index';

export default (store) => {

  function redirect(from, to) {
    return {
      path: from,
      onEnter: (nextState, transition) => {
        transition(to);
      }
    }
  }

  return {
    component: Root,
    childRoutes: [
      // 暂且跳转到 groups 页面
      redirect("/", "/home"),
      getRoute(store),

      {
        path: 'login(/:org_code)',
        component: LogIn
      },

      {
        path: 'getpwd(/:org_code)',
        component: GetPassword
      },

      {
        path: 'register/:org_code',
        component: Register
      },

      {
        path: 'logout',
        component: Logout
      },

      { // 404 Not Found
        path: '*',
        component: NotFound
      }
    ]
  };
};
